package com.excellent.ImageIdentification;

import org.json.JSONObject;

import java.util.Iterator;

public class Main {
    public static void main(String[] args) {
        try {
            String imagePath = "path/to/your/image.jpg";
            String accessToken = AuthUtils.getAccessToken();
            String imageBase64 = ImageUtils.encodeImageToBase64(imagePath);

            String ocrResult = OcrClient.recognizeText(imageBase64, accessToken);
            JSONObject jsonObject = new JSONObject(ocrResult);

            if (jsonObject.getInt("error_code") == 0) {
                JSONObject wordsResult = jsonObject.getJSONObject("words_result");
                for (Iterator it = wordsResult.keys(); it.hasNext(); ) {
                    String key = (String) it.next();
                    JSONObject line = wordsResult.getJSONObject(key);
                    System.out.println("Line " + key + ": " + line.getString("words"));
                }
            } else {
                System.out.println("OCR error: " + jsonObject.getString("error_msg"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
